<template>
  <div style="position: relative;">
    <el-form :inline="true" size="mini" :model="formInline" label-position="right">
      <el-form-item label="创建人">
        <el-input class="filter-item" v-model="formInline.createUserName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="所属部门">
        <el-cascader class="input-item" v-model="formInline.deptId" :clearable="true"
          placeholder="所属部门" :loading="loading"
          :props="dropdownprops"
          @visible-change="onDeptIdVisibleChange" :options="dropdownList"
          @change="onDeptIdValueChange">
        </el-cascader>
      </el-form-item>
      <el-form-item label="汇报类型">
        <el-select v-model="formInline.reportType" clearable placeholder="请选择">
          <el-option label="日报" :value="1"></el-option>
          <el-option label="周报" :value="2"></el-option>
          <el-option label="月报" :value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="formInline.readFlag" clearable placeholder="请选择">
          <el-option label="未读" :value="0"></el-option>
          <el-option label="已读" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">搜索</el-button>
        <el-button type="warning" class="el-button--reset" icon="el-icon-refresh-right" @click="resetFromdata" size="mini"></el-button>
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="24">
        <el-table :data="tableData" size="mini" style="width: 100%;" header-cell-class-name="table-header-gray" v-loading="isShowloading">
          <el-table-column type="index" align="center" width="55" label="序号"></el-table-column>
          <el-table-column prop="reportTypeName" align="center" label="汇报类型" show-overflow-tooltip></el-table-column>
          <el-table-column prop="deptName" align="center" label="所属部门" show-overflow-tooltip></el-table-column>
          <el-table-column prop="readFlagName" align="center" label="状态" show-overflow-tooltip></el-table-column>
          <el-table-column prop="createUserName" align="center" label="汇报人" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="createTime" align="center" label="创建时间" show-overflow-tooltip></el-table-column>
          <el-table-column prop="readTime" align="center" label="查看时间" width="140"></el-table-column>
          <el-table-column label="操作" align="center" width="220">
            <template slot-scope="scope">
              <el-button type="text" @click="handleInfo(scope.row)">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-row type="flex" justify="end" style="margin-top: 10px;">
          <el-pagination background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNo"
            :page-size="page_size"
            :page-sizes="[10, 20, 50, 100]"
            layout="total, prev, pager, next, sizes"
            :total="total"></el-pagination>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { WorkItems } from '@/api/workItems.js';
import { SysDeptController } from '@/api';
export default {
  name: 'Workreport',
  data () {
    return {
      dropdownList: [],
      dropdownprops: {
        label: 'deptName',
        value: 'deptId'
      },
      editDialogVisible: false,
      formInline: {
        createUserName: null,
        deptId: null,
        reportType: null,
        readFlag: null
      },
      tableData: [],
      total: 0,
      page_size: 10,
      pageNo: 1,
      loading: false,
      isShowloading: false
    }
  },
  mounted () {
    this.loadListWidgetData()
    this.loadDeptmentDropdownList()
  },
  activated () {
    this.loadListWidgetData()// 数据加载的方法
  },
  computed: {},
  methods: {
    /**
     * 所属部门下拉数据获取函数
     */
    loadDeptmentDropdownList () {
      return new Promise((resolve, reject) => {
        let params = {};
        SysDeptController.list(this, params).then(res => {
          this.dropdownList = res.data.dataList;
        }).catch(e => {
          reject(e);
        });
      });
    },
    /**
     * 所属部门下拉框显隐
     */
    onDeptIdVisibleChange (show) {

    },
    /**
     * 所属部门选中值改变
     */
    onDeptIdValueChange (value) {
      this.formInline.deptId = Array.isArray(value) ? value[value.length - 1] : undefined;
    },
    /**
     * 列表
     */
    loadListWidgetData () {
      let params = {
        ...this.formInline,
        size: this.page_size,
        current: this.pageNo
      }
      return new Promise((resolve, reject) => {
        WorkItems.list(this, params).then(res => {
          this.tableData = res.data.records
          this.total = res.data.total
        }).catch(e => {
          reject(e);
        });
      });
    },
    // 搜索
    onSubmit () {
      this.pageNo = 1
      this.loadListWidgetData()
    },
    // 重置
    resetFromdata () {
      this.formInline = {
        createUserName: null,
        deptId: null,
        reportType: null,
        readFlag: null
      }
      this.pageNo = 1
      this.page_size = 10
      this.loadListWidgetData()
    },
    // 分页导航
    handleCurrentChange (val) {
      this.pageNo = val
      this.loadListWidgetData()
    },
    handleSizeChange (val) {
      this.page_size = val
      this.loadListWidgetData()
    },
    currentChange (val) {
      this.pageNo = val
      this.loadListWidgetData()
    },
    // 查看
    handleInfo (row) {
      if (row.reportType === 1) {
        this.$router.push({path: '/Dailypaper', query: {reportId: row.id}})
      } else if (row.reportType === 2) {
        this.$router.push({path: '/Weeklypaper', query: {reportId: row.id}})
      } else {
        this.$router.push({path: '/Monthlypaper', query: {reportId: row.id}})
      }
    }
  }
}
</script>
